package com.hualude.roadsign.service.impl;

import com.aliyun.openservices.shade.com.alibaba.rocketmq.shade.com.alibaba.fastjson.JSON;
import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.repository.CountRepository;
import com.hualude.roadsign.service.CountService;
import com.hualude.roadsign.utils.ExportExcelUtil;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by anqian on 2017/4/7.
 */
@Service
public class CountServiceImpl implements CountService {
    @Resource
    private CountRepository countRepository;

    public DTResponseDto getRoadSign4DT(Integer userId, Integer orgId, DTRequestDto dtRequestDto) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String[] sQuery = convertParams(dtRequestDto.getSearch());
        // 0:时间 1:安装方式 2:板面固定 3:标志 4:维护公司
        Integer count = countRepository.getCount4DT(sQuery[0], sQuery[1], sQuery[2], sQuery[3], sQuery[4], authorityDto.getActor(), authorityDto.getOrgIds());
        List<RoadsignDto> dto4DTs = countRepository.getRoadSign4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds());
        DTResponseDto dtResponseDto = new DTResponseDto(dtRequestDto.getDraw(), count, count, dto4DTs);
        return dtResponseDto;
    }

    public Integer getRoadSignCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getRoadSignCount(orgId, actorId);
    }

    //得到用户公司及其子公司IDs，用户最终角色
    public AuthorityDto getActorAndOrgIds(AuthorityDto authorityDto) {
        try {
            String actorIds = countRepository.getactorIds(authorityDto.getUserId());
            String orgIds = authorityDto.getOrgId().toString();
            if (orgIds.equals("-1")) {
                orgIds = countRepository.getRealOrgIds(authorityDto.getUserId()).toString();
            }
            Integer actor = Integer.parseInt(actorIds.split(",")[0]);//用户最终角色 1系统>7主管>其它
            Integer isManager = actorIds.indexOf("1");//系统管理员
            Integer isChief = actorIds.indexOf("7");//主管管理员
            if (isManager >= 0) {
                actor = 1;
                String ChildOrgIds = countRepository.getOrgIds();
                if (!ChildOrgIds.equals("")) {
                    orgIds = ChildOrgIds;
                }
            } else if (isChief >= 0) {
                actor = 7;
                String ChildOrgIds = countRepository.getChildOrgIds(Integer.parseInt(orgIds));
                if (!ChildOrgIds.equals("")) {
                    orgIds += "," + ChildOrgIds;
                }
            }
            authorityDto.setActor(actor);
            authorityDto.setOrgIds(orgIds);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return authorityDto;
    }

    //“#”划分字符串
    public static String[] convertParams(String strQuery) {
        String[] strQueryParam = {"-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1"};
        try {
            if (!strQuery.equals("")) {
                strQueryParam = strQuery.split("#");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strQueryParam;
    }

    public Integer getRoadPoleCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getRoadPoleCount(orgId, actorId);
    }

    @Override
    public Integer getCoverCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getCoverCount(orgId, actorId);
    }

    @Override
    public Integer getHighLeverCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getHighLeverCount(orgId, actorId);
    }

    @Override
    public Integer getGuardrailCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getGuardrailCount(orgId, actorId);
    }

    @Override
    public Integer getMonitorCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getMonitorCount(orgId, actorId);
    }

    @Override
    public Integer getRoadLineCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getRoadLineCount(orgId, actorId);
    }

    @Override
    public Integer getSignalLampCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignalLampCount(orgId, actorId);
    }

    @Override
    public Integer getSignalMachineCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignalMachineCount(orgId, actorId);
    }

    @Override
    public Integer getSolarEnergyCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSolarEnergyCount(orgId, actorId);
    }

    public DTResponseDto getRoadPole4DT(Integer userId, Integer orgId, DTRequestDto dtRequestDto) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        Integer count = countRepository.getRoadPoleCount4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds());
        List<RoadpoleDto> dto4DTs = countRepository.getRoadPole4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds());
        DTResponseDto dtResponseDto = new DTResponseDto(dtRequestDto.getDraw(), count, count, dto4DTs);
        return dtResponseDto;
    }

    public List<String> getAllRoadName(String provinceName, String cityName, String areaName, Integer userId, Integer orgId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getRoadNames(provinceName, cityName, areaName, authorityDto.getOrgIds(), authorityDto.getActor());
    }

    public List<String> getAllAreaName(Integer userId, Integer orgId, String provinceName, String cityName) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getAllAreaName(authorityDto.getOrgIds(), provinceName, cityName);
    }

    public List<OrgDto> getAllOrg(Integer userId, Integer orgId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getAllOrg(authorityDto.getOrgIds());
    }

    public DTResponseDto getFault4DT(Integer userId, Integer orgId, DTRequestDto dtRequestDto) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        Integer count = countRepository.getFaultCount4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds());
        List<SignfaultDto> dto4DTs = countRepository.getFault4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds());
        DTResponseDto dtResponseDto = new DTResponseDto(dtRequestDto.getDraw(), count, count, dto4DTs);
        return dtResponseDto;
    }

    public DTResponseDto getMaintenance4DT(Integer userId, Integer orgId, DTRequestDto dtRequestDto) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        Integer count = countRepository.getMaintenanceCount4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        List<MaintenanceDto> dto4DTs = countRepository.getMaintenance4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        DTResponseDto dtResponseDto = new DTResponseDto(dtRequestDto.getDraw(), count, count, dto4DTs);
        return dtResponseDto;
    }

    public List<OrgDto> getDealOrg(Integer userId, Integer orgId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getDealOrg(authorityDto.getOrgIds());
    }

    public List<DealTalkCountsDto> getDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    public Integer getUnAuditSingCount(Integer orgId) throws Exception {
        return countRepository.getUnAuditSingCount(orgId);
    }

    public List<OrgDto> getConservationOrg(Integer mainOrgId, Integer userId, Integer orgId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getConservationOrg(mainOrgId, authorityDto.getOrgIds(), authorityDto.getActor());
    }

    public List<String> getProvinceName(Integer userId, Integer orgId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getProvinceName(authorityDto.getOrgIds());
    }

    public List<String> getCityName(Integer userId, Integer orgId, String provinceName) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getCityName(authorityDto.getOrgIds(), provinceName);
    }

    public List<String> getStartRoadName(Integer userId, Integer orgId, String provinceName, String cityName, String areaName,
                                         String endRoadName, String roadName) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        List<String> roadStartName = countRepository.getStartRoadName(authorityDto.getOrgIds(), provinceName, cityName,
                areaName, endRoadName, roadName);
        return roadStartName;
    }

    public List<String> getEndRoadName(Integer userId, Integer orgId, String startRoad, String provinceName, String cityName,
                                       String areaName, String roadName) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        return countRepository.getEndRoadName(authorityDto.getOrgIds(), startRoad, provinceName, cityName, areaName, roadName);
    }

    public List<Integer> getPerSignCounts(Integer userId, Integer orgId, String time, String province, String city, String area, String road) throws Exception {
        if (province.equals("-1")) province = "";
        if (city.equals("-1")) city = "";
        if (area.equals("-1")) area = "";
        if (road.equals("-1")) road = "";
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        if (orgId == -1) {
            if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
                orgIds = authorityDto.getOrgIds();
            }
        }
        return countRepository.getPerSignCounts(orgIds, time, province, city, area, road);
    }

    public DTResponseDto getRoadSignPole4DT(Integer userId, Integer orgId, DTRequestDto dtRequestDto) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        Integer count = countRepository.getRoadSignPole4DTCount(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        List<RoadpoleDto> dto4DTs = countRepository.getRoadSignPole4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        List<BigInteger> counts = countRepository.getRoadSignCounts(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        for (int i = 0; i < dto4DTs.size(); i++) {
            dto4DTs.get(i).setRoadSignCount(counts.get(i).intValue());
        }
        DTResponseDto dtResponseDto = new DTResponseDto(dtRequestDto.getDraw(), count, count, dto4DTs);
        return dtResponseDto;
    }

    public List<NameCountDto> getAreaRoadSignCount(Integer userId, Integer orgId, String roadSignCity) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        if (orgId == -1) {
            if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
                orgIds = authorityDto.getOrgIds();
            }
        }
        List<NameCountDto> nameCountDtos = countRepository.getAreaRoadSignCount(orgIds, roadSignCity);
        return nameCountDtos;
    }

    public List<Integer> getPerSignCountsByRoad(String province, String city, String area, String orgName, String roadName) throws Exception {
        return countRepository.getPerSignCountsByRoad(province, city, area, orgName, roadName);
    }

    public HSSFWorkbook downSignPoleByExcel(String search, Integer userId, Integer orgId) throws Exception {
        DTRequestDto dtRequestDto = new DTRequestDto(0, 0, 0, search);
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        List<RoadpoleDto> dto4DTs = countRepository.getRoadSignPole4DT(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        List<BigInteger> counts = countRepository.getRoadSignCounts(dtRequestDto, authorityDto.getActor(), authorityDto.getOrgIds(), authorityDto.getUserId());
        for (int i = 0; i < dto4DTs.size(); i++) {
            dto4DTs.get(i).setRoadSignCount(counts.get(i).intValue());
        }
        for (RoadpoleDto roadpoleDto : dto4DTs) {
            Integer[] type = {0, 0, 0, 0, 0, 0, 0, 0};
            List<Integer> roadSignType = countRepository.getPerSignCountsByRoad(roadpoleDto.getProvince(),
                    roadpoleDto.getCity(), roadpoleDto.getArea(), roadpoleDto.getOrgName(), roadpoleDto.getRoadName());
            for (int i = 0; i < roadSignType.size(); i++)
                type[roadSignType.get(i)]++;
            roadpoleDto.setSignType(type);
        }
        //表头String数组
        String[] excelHeader = new String[]{"序号", "维护公司", "省份", "市", "区域", "道路", "标牌总数", "警告标志", "禁令标志", "指示标志", "指路标志", "旅游标志", "辅助标志", "作业标志", "告示标志"};
        //创建工具类对象
        ExportExcelUtil excelUtil = new ExportExcelUtil();
        //创建样式
        HSSFCellStyle style = excelUtil.createExStyle("宋体", 10, HSSFFont.BOLDWEIGHT_NORMAL, HSSFCellStyle.ALIGN_CENTER, HSSFCellStyle.VERTICAL_CENTER);
        HSSFCellStyle headStyle = excelUtil.createExStyle("宋体", 10, HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER, HSSFCellStyle.VERTICAL_CENTER);
        //添加边框
        excelUtil.setBorder(style);
        excelUtil.setBorder(headStyle);
        //创建工作表
        HSSFSheet sheet = excelUtil.createExSheet("sheet1", 300, 15);
        //添加表头
        excelUtil.createExSheetHeader(sheet, headStyle, 0, excelHeader);
        //添加内容
        for (int i = 0; i < dto4DTs.size(); i++) {
            HSSFRow row = sheet.createRow(i + 1);
            excelUtil.addExInfo(row, 0, style, i + 1);
            excelUtil.addExInfo(row, 1, style, dto4DTs.get(i).getOrgName());
            excelUtil.addExInfo(row, 2, style, dto4DTs.get(i).getProvince());
            excelUtil.addExInfo(row, 3, style, dto4DTs.get(i).getCity());
            excelUtil.addExInfo(row, 4, style, dto4DTs.get(i).getArea());
            excelUtil.addExInfo(row, 5, style, dto4DTs.get(i).getRoadName());
            excelUtil.addExInfo(row, 6, style, dto4DTs.get(i).getRoadSignCount());
            excelUtil.addExInfo(row, 7, style, dto4DTs.get(i).getSignType()[0]);
            excelUtil.addExInfo(row, 8, style, dto4DTs.get(i).getSignType()[1]);
            excelUtil.addExInfo(row, 9, style, dto4DTs.get(i).getSignType()[2]);
            excelUtil.addExInfo(row, 10, style, dto4DTs.get(i).getSignType()[3]);
            excelUtil.addExInfo(row, 11, style, dto4DTs.get(i).getSignType()[4]);
            excelUtil.addExInfo(row, 12, style, dto4DTs.get(i).getSignType()[5]);
            excelUtil.addExInfo(row, 13, style, dto4DTs.get(i).getSignType()[6]);
            excelUtil.addExInfo(row, 14, style, dto4DTs.get(i).getSignType()[7]);
        }
        return excelUtil.getHssfWorkbook();
    }

    @Override
    public Integer getSignFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignFaultCount(orgId, actorId);
    }

    @Override
    public Integer getCoverAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getCoverAuditCount(orgId, actorId);
    }

    @Override
    public Integer getCoverFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getCoverFaultCount(orgId, actorId);
    }

    @Override
    public Integer getHighLeverAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getHighLeverAuditCount(orgId, actorId);
    }

    @Override
    public Integer getHighLeverFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getHighLeverFaultCount(orgId, actorId);
    }

    @Override
    public Integer getGuardrailAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getGuardrailAuditCount(orgId, actorId);
    }

    @Override
    public Integer getGuardrailFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getGuardrailFaultCount(orgId, actorId);
    }

    @Override
    public Integer getMonitorAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getMonitorAuditCount(orgId, actorId);
    }

    @Override
    public Integer getMonitorFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getMonitorFaultCount(orgId, actorId);
    }

    @Override
    public Integer getRoadLineAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getRoadLineAuditCount(orgId, actorId);
    }

    @Override
    public Integer getRoadLineFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getRoadLineFaultCount(orgId, actorId);
    }

    @Override
    public Integer getSignalLampAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignalLampAuditCount(orgId, actorId);
    }

    @Override
    public Integer getSignalLampFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignalLampFaultCount(orgId, actorId);
    }

    @Override
    public Integer getSignalMachineAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignalMachineAuditCount(orgId, actorId);
    }

    @Override
    public Integer getSignalMachineFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSignalMachineFaultCount(orgId, actorId);
    }

    @Override
    public Integer getSolarEnergyAuditCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSolarEnergyAuditCount(orgId, actorId);
    }

    @Override
    public Integer getSolarEnergyFaultCount(Integer orgId, Integer actorId) throws Exception {
        return countRepository.getSolarEnergyFaultCount(orgId, actorId);
    }

    @Override
    public List<DealTalkCountsDto> getCoverDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getCoverOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getCoverOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getCoverOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getHighLeverDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getHighLeverOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getHighLeverOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getHighLeverOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getGuardrailDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getGuardrailOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getGuardrailOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getGuardrailOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getMonitorDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getMonitorOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getMonitorOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getMonitorOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getRoadLineDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getRoadLineOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getRoadLineOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getRoadLineOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getSignLampDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getSignLampOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getSignLampOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getSignLampOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getSignalMachineDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getSignalMachineOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getSignalMachineOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getSignalMachineOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public List<DealTalkCountsDto> getSolarEnergyDealTalkTimes(Integer year, Integer orgId, Integer userId) throws Exception {
        AuthorityDto authorityDto = new AuthorityDto(userId, orgId);
        authorityDto = getActorAndOrgIds(authorityDto);
        String orgIds = orgId.toString();
        //if (orgId == -1)
        if (authorityDto.getActor() == 7 || authorityDto.getActor() == 1) {
            orgIds = authorityDto.getOrgIds();
        }
        List<String> dealTimes = countRepository.getSolarEnergyOrgYearDealTimes(year, orgIds);
        List<String> talkTimes = countRepository.getSolarEnergyOrgyearTalkTimes(year, orgIds);
        List<MaintenanceDto> spendMoney = countRepository.getSolarEnergyOrgyearSpendMoney(year, orgIds);
        List<DealTalkCountsDto> dealCountDtos = new ArrayList<>(dealTimes.size());
        List<DealTalkCountsDto> TalkCountDtos = new ArrayList<>(talkTimes.size());
        List<DealTalkCountsDto> spendMoneyDtos = new ArrayList<>(spendMoney.size());
        for (String time : dealTimes) {
            dealCountDtos.add(new DealTalkCountsDto(1, time));
        }
        for (String time : talkTimes) {
            TalkCountDtos.add(new DealTalkCountsDto(0, time));
        }

        for (int i = 0; i < spendMoney.size(); i++) {
            double repairAmount = 0;
            if (spendMoney.get(i).getRepairAmount() != null) {
                repairAmount = spendMoney.get(i).getRepairAmount();
                BigDecimal b = new BigDecimal(repairAmount);
                repairAmount = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            }
            spendMoneyDtos.add(new DealTalkCountsDto(2, spendMoney.get(i).getMaintenanceTime(), repairAmount));
        }
        dealCountDtos.addAll(TalkCountDtos);
        dealCountDtos.addAll(spendMoneyDtos);
        return dealCountDtos;
    }

    @Override
    public PositionDto getAllInfo4Type(Integer orgId, Integer orgType, Integer EquipmentType, String actorIds) throws Exception {
        PositionDto dto = new PositionDto();
        String orgIds = "";
        if (!actorIds.contains("1")) {
            List<OrgFatherAndChildDto> orgList;
            List<OrgFatherAndChildDto> orgInfo = countRepository.getOrgIdNameByOrgId(orgId);

            if (orgType == 1) {
                orgList = countRepository.getChildOrgIdNameByOrgId(orgId);
                dto.setOrg(orgList);
                dto.setMainOrg(orgInfo);
                for (OrgFatherAndChildDto org : orgList) {
                    orgIds += org.getOrgId().toString() + ",";
                }//当前用户为监管公司时 查询子公司
            } else {
                orgList = countRepository.getMainOrgNameByOrgId(orgId);
                dto.setOrg(orgInfo);
                dto.setMainOrg(orgList);
                orgIds = orgId.toString() + ",";
            }//当前用户为子公司时 就查询该公司

        } else {//管理员获取所有公司
            List<OrgFatherAndChildDto> companyOrgList = countRepository.getAllCompanyOrgIdName();
            List<OrgFatherAndChildDto> mainOrgList = countRepository.getAllMainOrgIdName();
            for (OrgFatherAndChildDto org : companyOrgList) {
                orgIds += org.getOrgId().toString() + ",";
            }//当前用户为监
            dto.setOrg(companyOrgList);
            dto.setMainOrg(mainOrgList);
        }
        orgIds = orgIds.substring(0, orgIds.length() - 1);
        dto.setProvince(countRepository.getAllInfo4Type("Province", EquipmentType, orgIds));
        dto.setArea(countRepository.getAllInfo4Type("Area", EquipmentType, orgIds));
        dto.setCity(countRepository.getAllInfo4Type("City", EquipmentType, orgIds));
        dto.setRoadName(countRepository.getAllInfo4Type("RoadName", EquipmentType, orgIds));
        dto.setStartRoad(countRepository.getAllInfo4Type("StartRoad", EquipmentType, orgIds));
        dto.setEndRoad(countRepository.getAllInfo4Type("EndRoad", EquipmentType, orgIds));
        return dto;
    }

    @Override
    public DTResponseDto getCount4Type(DTRequestDto dtRequestDto) throws Exception {
        if (dtRequestDto.getSearch().equals("null"))
            return new DTResponseDto(dtRequestDto.getDraw(), 0, 0, "");
        ColligateDto dto = JSON.parseObject(dtRequestDto.getSearch(), ColligateDto.class);
        List<ColligateDto> colligateDto = new ArrayList<ColligateDto>();
        Integer count = 0;
        switch (dto.getType()) {
            case 0:
                colligateDto = countRepository.getAllRoadPoleCountDT(dtRequestDto, dto);
                count = countRepository.getAllRoadPoleCount(dtRequestDto, dto);
                break;
            case 1:
                colligateDto = countRepository.getAllRoadSignCountDT(dtRequestDto, dto);
                count = countRepository.getAllRoadSignCount(dtRequestDto, dto);
                break;
            case 2:
                colligateDto = countRepository.getAllSignalLampCountDT(dtRequestDto, dto);
                count = countRepository.getAllSignalLampCount(dtRequestDto, dto);
                break;
            case 3:
                colligateDto = countRepository.getAllSignalMachineCountDT(dtRequestDto, dto);
                count = countRepository.getAllSignalMachineCount(dtRequestDto, dto);
                break;
            case 4:
                colligateDto = countRepository.getAllSolarEnergyCountDT(dtRequestDto, dto);
                count = countRepository.getAllSolarEnergyCount(dtRequestDto, dto);
                break;
            case 5:
                colligateDto = countRepository.getAllHighLeverCountDT(dtRequestDto, dto);
                count = countRepository.getAllHighLeverCount(dtRequestDto, dto);
                break;
            case 6:
                colligateDto = countRepository.getAllRoadLineCountDT(dtRequestDto, dto);
                count = countRepository.getAllRoadLineCount(dtRequestDto, dto);
                break;
            case 7:
                colligateDto = countRepository.getAllGuardrailCountDT(dtRequestDto, dto);
                count = countRepository.getAllGuardrailCount(dtRequestDto, dto);
                break;
            case 8:
                colligateDto = countRepository.getAllMonitorCountDT(dtRequestDto, dto);
                count = countRepository.getAllMonitorCount(dtRequestDto, dto);
                break;
            case 9:
                colligateDto = countRepository.getAllCoverCountDT(dtRequestDto, dto);
                count = countRepository.getAllCoverCount(dtRequestDto, dto);
                break;
        }
        return new DTResponseDto(dtRequestDto.getDraw(), count, count, colligateDto);

    }

    @Override
    public DTResponseDto getFault4Type(DTRequestDto dtRequestDto) throws Exception {
        if (dtRequestDto.getSearch().equals("null"))
            return new DTResponseDto(dtRequestDto.getDraw(), 0, 0, "");
        ColligateDto dto = JSON.parseObject(dtRequestDto.getSearch(), ColligateDto.class);
        String faultType = "";

        List<ColligateDto> colligateDto = new ArrayList<ColligateDto>();
        Integer count = 0;
        switch (dto.getType()) {
            case 1:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.CompanyCheck=0 ";
                        dto.setFaultType(faultType);
                        colligateDto = countRepository.getAllRoadSignFaultDT(dtRequestDto, dto);
                        count = countRepository.getAllRoadSignFaultCount(dtRequestDto, dto);
                        break;
                    case "2":
                        faultType = "and e.MainCheck=0 and e.CompanyCheck=1 ";
                        dto.setFaultType(faultType);
                        colligateDto = countRepository.getAllRoadSignFaultDT(dtRequestDto, dto);
                        count = countRepository.getAllRoadSignFaultCount(dtRequestDto, dto);
                        break;
                    case "3":
                        faultType = "and e.MaintenanceStatus=1 ";
                        dto.setFaultType(faultType);
                        colligateDto = countRepository.getAllRoadSignMainFaultDT(dtRequestDto, dto);
                        count = countRepository.getAllRoadSignFaulMaintCount(dtRequestDto, dto);
                        break;
                    case "4":
                        faultType = "and e.MaintenanceStatus=2 ";
                        dto.setFaultType(faultType);
                        colligateDto = countRepository.getAllRoadSignMainFaultDT(dtRequestDto, dto);
                        count = countRepository.getAllRoadSignFaulMaintCount(dtRequestDto, dto);
                        break;
                    default:
                        faultType = "";
                        break;
                }

                break;
            case 2:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.LampCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.LampMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.LampMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.LampMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllSignalLampFaultDT(dtRequestDto, dto);
                count = countRepository.getAllSignalLampFaultCount(dtRequestDto, dto);
                break;
            case 3:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.MachineCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.MachineMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.MachineMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.MachineMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllSignalMachineFaultDT(dtRequestDto, dto);
                count = countRepository.getAllSignalMachineFaultCount(dtRequestDto, dto);
                break;
            case 4://
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.SolarCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.SolarMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.SolarMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.SolarMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllSolarEnergyFaultDT(dtRequestDto, dto);
                count = countRepository.getAllSolarEnergyFaultCount(dtRequestDto, dto);
                break;
            case 5:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.HighLeverCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.HighLeverMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.HighLeverMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.HighLeverMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllHighLeverFaultDT(dtRequestDto, dto);
                count = countRepository.getAllHighLeverFaultCount(dtRequestDto, dto);
                break;
            case 6:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.RoadLineCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.RoadLineMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.RoadLineMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.RoadLineMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllRoadLineFaultDT(dtRequestDto, dto);
                count = countRepository.getAllRoadLineFaultCount(dtRequestDto, dto);
                break;
            case 7:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.GuardrailCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.GuardrailMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.GuardrailMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.GuardrailMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllGuardrailFaultDT(dtRequestDto, dto);
                count = countRepository.getAllGuardrailFaultCount(dtRequestDto, dto);
                break;
            case 8://
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.MonitorCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.MonitorMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.MonitorMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.MonitorMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllMonitorFaultDT(dtRequestDto, dto);
                count = countRepository.getAllMonitorFaultCount(dtRequestDto, dto);
                break;
            case 9:
                switch (dto.getFaultType()) {
                    case "1":
                        faultType = "and e.CoverCheck=0 ";
                        break;
                    case "2":
                        faultType = "and e.CoverMainCheck=0 ";
                        break;
                    case "3":
                        faultType = "and e.CoverMaintenanceStatus=1 ";
                        break;
                    case "4":
                        faultType = "and e.CoverMaintenanceStatus=2 ";
                        break;
                    default:
                        faultType = "";
                        break;
                }
                dto.setFaultType(faultType);
                colligateDto = countRepository.getAllCoverFaultDT(dtRequestDto, dto);
                count = countRepository.getAllCoverFaultCount(dtRequestDto, dto);
                break;
        }
        return new DTResponseDto(dtRequestDto.getDraw(), count, count, colligateDto);
    }

}
